package com.loveprogrammer.model.goods;

import com.loveprogrammer.engine.enums.EquipmentEnum;
import com.loveprogrammer.engine.enums.QualityEnum;
import com.loveprogrammer.engine.enums.WeaponTypeEnum;
import com.loveprogrammer.utils.ConsoleColors;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @version 1.0.0
 * @description: 装备
 * @author: eric
 * @date: 2022-08-03 10:43
 **/
@Data
public class Equipment extends Goods {

    private int suitId;                   // 如果是套装，套装的id
    private int strength;                  // 力量 影响物理输出 物理技能输出
    private int armature;                 // 护甲值 影响物理防御和法术防御
    private int constitution;               // 体质 影响生命值 一点体质增加10点生命值
    private int magic;                       // 魔力 影响法术输出 法术技能输出
    private int technique;                   // 技巧 影响闪避率、暴击率
    private int speed;                         // 攻击速度

    private int hp;                            // 生命值
    private int evasion;

    private int fortune;

    private boolean used = false;   // 是否被使用

    // 如果constant == true，不能增加前缀，属于固定属性装备
    private boolean constant = false;

    // 如果specifyDrop == true，只有特定的副本或者特定的野怪才能掉落
    private boolean specifyDrop = false;

    // 武器位置
    public EquipmentEnum equipmentPosition;

    // 武器类型
    private WeaponTypeEnum weaponTypeEnum;

    // 用于计算和当前装备相比的属性差异
    private int difference;

    public Equipment(String name, String type, String desc, QualityEnum quality, int strength,
                     int armature, int constitution, int magic, int technique, int speed, int hp,
                     int evasion, int fortune, boolean used, boolean constant, boolean specifyDrop,
                     EquipmentEnum equipmentPosition, List<String> affixList,
                     WeaponTypeEnum weaponTypeEnum, int suitId, int level, int poisonResistance,
                     int flameResistance, int thunderResistance, int iceResistance,  int goodsId) {
        this(name, type, desc, quality, strength, armature, constitution, magic, technique, speed,
                hp, evasion, fortune, used, equipmentPosition, weaponTypeEnum, affixList, level,
                poisonResistance,flameResistance,thunderResistance,iceResistance,goodsId);
        this.constant = constant;
        this.specifyDrop = specifyDrop;
        this.suitId = suitId;
    }

    public Equipment(String name, String type, String desc, QualityEnum quality, int strength,
                     int armature, int constitution, int magic, int technique, int speed, int hp,
                     int evasion, int fortune, boolean used, EquipmentEnum equipmentPosition,
                     WeaponTypeEnum weaponTypeEnum, List<String> affixList, int level,
                     int poisonResistance, int flameResistance, int thunderResistance, int iceResistance,
                     int goodsId) {
        super(name, type, desc, quality, level,poisonResistance,flameResistance,
                thunderResistance,iceResistance,goodsId);
        this.strength = strength;
        this.armature = armature;
        this.constitution = constitution;
        this.magic = magic;
        this.technique = technique;
        this.speed = speed;
        this.hp = hp;
        this.evasion = evasion;
        this.fortune = fortune;
        this.equipmentPosition = equipmentPosition;
        this.weaponTypeEnum = weaponTypeEnum;
        this.used = used;
        if(affixList == null){
            affixList = new ArrayList<>();
        }
    }

    public Equipment(String name, String type, String desc, EquipmentEnum equipmentEnum,
                     QualityEnum quality, int goodsId) {
        super(name, type, desc, quality,goodsId);
        this.equipmentPosition = equipmentEnum;
    }

    // 物品打印信息的重写
    @Override
    public String toString() {
        return "*物品信息* " +
                "名称：" + getName() + " " + "级别：" + getLevel() + " " +
                "品质：" + this.quality.getColor() + this.quality.getDesc() + ConsoleColors.RESET + " " +
                (strength > 0 ? ("力量：" + strength + " ") : "") +
                (armature > 0 ? ("护甲：" + armature + " ") : "") +
                (constitution > 0 ? ("体力：" + constitution + " ") : "") +
                (magic > 0 ? ("魔力：" + magic + " ") : "") +
                (technique > 0 ? ("技巧：" + technique + " ") : "") +
                (speed > 0 ? ("速度：" + speed + " ") : "") +
                (getPoisonResistance() > 0 ? ("毒抗：" + getPoisonResistance() + " ") : "") +
                (getFlameResistance() > 0 ? ("火抗：" + getFlameResistance() + " ") : "") +
                (getThunderResistance() > 0 ? ("雷抗：" + getThunderResistance() + " ") : "") +
                (getIceResistance() > 0 ? ("冰抗：" + getIceResistance() + " ") : "") +
                "；";
    }

    // 物品打印信息的重写
    public String prettyPrint() {
        return string + "****物品信息****\n" +
                string + "名称：" + getName() + "\n" +
                string + "品质：" + this.quality.getColor() + this.quality.getDesc() + ConsoleColors.RESET + "\n" +
                string + "位置：" + Optional.ofNullable(this.getEquipmentPosition()).orElse(EquipmentEnum.UNKOWN).getDesc() + "\n" +
                string + "说明：" + getDesc() + "\n" +
                (strength > 0 ? (string + "力量：" + strength + "\n") : "") +
                (armature > 0 ? (string + "护甲：" + armature + "\n") : "") +
                (constitution > 0 ? (string + "体力：" + constitution + "\n") : "") +
                (magic > 0 ? (string + "魔力：" + magic + "\n") : "") +
                (technique > 0 ? (string + "技巧：" + technique + "\n") : "") +
                (speed > 0 ? (string + "速度：" + speed + "\n") : "") +
                (getPoisonResistance() > 0 ? (string + "毒抗：" + getPoisonResistance() + "\n") : "") +
                (getFlameResistance() > 0 ? (string + "火抗：" + getFlameResistance() + "\n") : "") +
                (getThunderResistance() > 0 ? (string + "雷抗：" + getThunderResistance() + "\n") : "") +
                (getIceResistance() > 0 ? (string + "冰抗：" + getIceResistance() + "\n") : "") +
                string + "" + "***************";
    }

}
